<!--
	o   This page will be loaded from clicking on a search result in the Search Page.
	o   Will display all the necessary information about the house and contain
	o   Will contain all buttons required to include functionalities for buyers, sellers, administrators and other parties.
-->
<h1>Property View Page</h1>
<?php
	include('connect.php');
//	include('calendar.php');

//if(isset($_POST["appointment"]) && $_POST["appointment"] == "yes")
//{	

/*	$sqlQuery = "SELECT USRID_SELLS FROM PROPERTY WHERE PRTID = ".$_SESSION['PRTID'].";";

	$result = mysql_query($sqlQuery);
	
	if(!$result)
		{
			echo '<br />ERROR535 ';
			die('SQL Command Error: ' . mysql_error());
		}
		
	$row = mysql_fetch_assoc($result);
	$sqlQuery = "INSERT INTO COMMUNICATIONS VALUES (NULL,NOW(),'You have an appointment request!','test','NO',".$row["USRID_SELLS"].", ".$_SESSION['PRTID'].")";
	$result = mysql_query($sqlQuery);
*/
//}

if(isset($_SESSION['PRTID']) && !isset($_POST['PRTID']))
{
	$PRTID = $_SESSION['PRTID'];
}else{

	if(isset($_POST['PRTID']))
	{
		$PRTID = $_POST['PRTID'];
		$_SESSION['PRTID'] = $PRTID;
	}
}

/*if(isset($_POST["CalDates"]))
{
	echo'<br /><br /> Caldates : ';
	print_r($_POST["CalDates"]);
	$CalDates = $_POST["CalDates"];
}

//var_dump ($_POST);
$d = getdate(time()); 
if(isset($_POST["month"]))
{
	$month = $_POST["month"];
}else{
	$month = $d["mon"];
}

if(isset($_POST["year"]))
{
	$year = $_POST["year"];
}else{
	$year = $d["year"];
}*/

$colquery = "SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME='PROPERTY';";
$colresult = mysql_query($colquery);

$colsRoomResult = mysql_query("SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME='ROOMS'");
$colsImprovResult = mysql_query("SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME='IMPROVEMENTS'");

$cols = mysql_num_rows($colresult);
$colsRooms = mysql_num_rows($colsRoomResult);
$colsImprov = mysql_num_rows($colsImprovResult);

$adrcolquery = "SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME='ADDRESS';";
$adrcolresult = mysql_query($adrcolquery);
$adrcols = mysql_num_rows($adrcolresult);

if(isset($_POST['delete']))
{
	$sql = "DELETE FROM PROPERTY WHERE $PRTID=PRTID;";
	$result = mysql_query($sql);
	if(!$result) echo "Delete Failed: $sql <br />" . mysql_error() . "<br /> <br />";
	else echo "Delete successful";
}
elseif(isset($_POST['saveadd']) && checkfields_add())
{
	$insertquery = "INSERT INTO PROPERTY ";
	$attr = "";
	$vals = "";
	$ADRID = "";
	for ($i = 0 ; $i < $cols ; ++$i)
	{
		$colname = mysql_result($colresult,$i,'COLUMN_NAME');
		
		switch($colname)
		{
			case 'ADRID':
			{
				$adrinsertquery = "INSERT INTO ADDRESS ";
				$adrattr = "";
				$adrvals = "";
				for ($j = 0 ; $j < $adrcols ; ++$j)
				{
					$adrcolname = mysql_result($adrcolresult,$j,'COLUMN_NAME');
					if ($adrcolname != $colname)
					{
						if(strlen($_POST[$adrcolname]) > 0) $adrvals .= '"' . $_POST[$adrcolname] . '"';
						else $adrvals .= 'NULL';
						$adrattr .= $adrcolname;		
						if($j < $adrcols - 1) 
						{
							$adrvals .= ",";
							$adrattr .= ",";
						}
					}
				}
				$adrinsertquery .= "(" . $adrattr . ") VALUES (" . $adrvals . ");";
				if (!mysql_query($adrinsertquery))
					echo "Save Failed: $adrinsertquery <br />" . mysql_error() . "<br /> <br />";
				$ADRID = mysql_insert_id();
				break;
			}
			default:
			{
				if ($colname != 'USRID_SELLS' && $colname != 'USRID_BUYS' && $colname != 'PRTID')
				{
					if(strlen($_POST[$colname]) > 0) $vals .= '"' . $_POST[$colname] . '",';
					else $vals .= 'NULL,';
					$attr .= $colname.",";
				}
				
				break;
			}
		}
	}
	$vals .= "'" . $ADRID . "','" . $_SESSION['USRID'] . "'";
	$attr .= 'ADRID , USRID_SELLS';
	$insertquery .=  "(" . $attr . ") VALUES (" . $vals . ");";	
	if (!mysql_query($insertquery))
		echo "Save Failed: $insertquery <br />" . mysql_error() . "<br /> <br />";
	
	$PRTID = mysql_insert_id();

	$EXPIRY_DATE = $_POST['EXPIRY_DATE'];
	$SELLING_PRICE = $_POST['ASKING_PRICE'];
	$UAGID = 1; /*TODO*/

	$query = "INSERT INTO LISTS(LISTING_DATE, EXPIRY_DATE, SELLING_PRICE, PRTID, UAGID)
				VALUES (NOW(), '$EXPIRY_DATE', '$SELLING_PRICE', '$PRTID', 
'$UAGID')";
	if (!mysql_query($query))
		echo "Save Failed: $query <br />" . mysql_error() . "<br /> <br />";
}

elseif(isset($_POST['save']))
{
	$resultRoom = mysql_query("SELECT * FROM ROOMS WHERE PRTID ='$PRTID';");
	if (!$resultRoom) die ("Database access failed: " . mysql_error());
	$resultImprov = mysql_query("SELECT * FROM IMPROVEMENTS WHERE PRTID ='$PRTID';");
	if (!$resultImprov) die ("Database access failed: " . mysql_error());

	$updatequery = "UPDATE PROPERTY SET ";
	for ($i = 0 ; $i < $cols ; ++$i)
	{
		$colname = mysql_result($colresult,$i,'COLUMN_NAME');
		
		switch($colname)
		{
			case 'ADRID':
			{
				$adrupdatequery = "UPDATE ADDRESS SET ";
				for ($j = 0 ; $j < $adrcols ; ++$j)
				{
					$adrcolname = mysql_result($adrcolresult,$j,'COLUMN_NAME');
					if ($adrcolname != $colname)
					{
						if(strlen($_POST[$adrcolname]) > 0) $new_val = '"' . $_POST[$adrcolname] . '"';
						else $new_val = 'NULL';
						$adrupdatequery = $adrupdatequery . " $adrcolname=$new_val";		
						if($j < $adrcols - 1) $adrupdatequery = $adrupdatequery . ",";		
					}
				}
				$adrupdatequery = $adrupdatequery . " WHERE $colname = (SELECT $colname FROM `PROPERTY` WHERE PRTID 
= $PRTID);";
				if (!mysql_query($adrupdatequery))
					echo "Save Failed: $adrupdatequery <br />" . mysql_error() . "<br /> <br />";
				
				break;
			}
			default:
			{
				if ($colname != 'USRID_SELLS' && $colname != 'USRID_BUYS' && $colname != 'PRTID')
				{
					if(strlen($_POST[$colname]) > 0) $new_val = '"' . $_POST[$colname] . '"';
					else $new_val = 'NULL';
					$updatequery = $updatequery . " $colname=$new_val";
					$updatequery = $updatequery . ",";
				}
				
				break;
			}
		}
	}
	
	$updatequery = substr($updatequery,0,strlen($updatequery)-1);
	$updatequery = $updatequery . " WHERE PRTID=$PRTID;";
	if (!mysql_query($updatequery))
		echo "Save Failed: $updatequery <br />" . mysql_error() . "<br /> <br />";
	
	$x=0;
	
	while($row = mysql_fetch_assoc($resultRoom))
	{
		$updatequery = "UPDATE ROOMS SET ";
		
		for ($i = 0 ; $i < $colsRooms ; ++$i)
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			
			switch($colname)
			{
				default:
				{
					if ($colname != 'ROMID' && $colname != 'PRTID')
					{
						if(strlen($_POST[$colname.$x]) > 0) $new_val = '"' . $_POST[$colname.$x] . '"';
						else $new_val = 'NULL';
						$updatequery = $updatequery . " $colname=$new_val";
						$updatequery = $updatequery . ",";
					}
					
					break;
				}
			}
		}
		
		$updatequery = substr($updatequery,0,strlen($updatequery)-1);
		$updatequery = $updatequery . " WHERE ROMID=".$row["ROMID"];
		
		//echo '<br />Update Query : '. $updatequery;
		if (!mysql_query($updatequery))
			echo "Save Failed: $updatequery <br />" . mysql_error() . "<br /> <br />";
		$x++;	
	}	
	if(isset($_POST['DESCRIPTION'.$x]))
	{
		$attr = "";
		$vals = "";
		for ($i = 0 ; $i < $colsRooms ; ++$i)
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				$vals .= "'" .$_POST[$colname.$x] . "',";
				$attr .=  $colname . ",";
			}
		}
		$attr .= 'PRTID';
		$vals .= $PRTID;
		$query = "INSERT INTO ROOMS($attr) VALUES($vals);";
		if (!mysql_query($query))
			echo "Save Failed: $updatequery <br />" . mysql_error() . "<br /> <br />";
	}
	$x=0;
	
	while($row = mysql_fetch_assoc($resultImprov))
	{
		$updatequery = "UPDATE IMPROVEMENTS SET ";
		
		for ($i = 0 ; $i < $colsImprov ; ++$i)
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			
			switch($colname)
			{
				default:
				{
					if ($colname != 'IMTID' && $colname != 'PRTID')
					{
						if(strlen($_POST[$colname.$x]) > 0) $new_val = '"' . $_POST[$colname.$x] . '"';
						else $new_val = 'NULL';
						$updatequery = $updatequery . " $colname=$new_val";
						$updatequery = $updatequery . ",";
					}
					
					break;
				}
			}
		}
		
		$updatequery = substr($updatequery,0,strlen($updatequery)-1);
		$updatequery = $updatequery . " WHERE IMTID=".$row["IMTID"];
		
		//echo '<br />Update Query : '. $updatequery;
		if (!mysql_query($updatequery))
			echo "Save Failed: $updatequery <br />" . mysql_error() . "<br /> <br />";
		$x++;	
	}
	if(isset($_POST['DESCRIPTION'.$x]))
	{
		$attr = "";
		$vals = "";
		for ($i = 0 ; $i < $colsImprov ; ++$i)
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				$vals .= "'" .$_POST[$colname.$x] . "',";
				$attr .=  $colname . ",";
			}
		}
		$attr .= 'PRTID';
		$vals .= $PRTID;
		$query = "INSERT INTO IMPROVEMENTS($attr) VALUES($vals);";
		if (!mysql_query($query))
			echo "Save Failed: $updatequery <br />" . mysql_error() . "<br /> <br />";
	}
}

// Delete
$deletemode = isset($_POST['delete']);
// Adding
$addmode = isset($_POST['add']);
// Editing
$editmode = isset($_POST['edit']) || isset($_POST['addimprov']) || isset($_POST['addroom']) ;

if(!$addmode && !$deletemode)
{
	$query = "SELECT * FROM PROPERTY WHERE PRTID='$PRTID';";
	$result = mysql_query($query);
	if (!$result) die ("Database access failed: " . mysql_error());
	$row = mysql_fetch_row($result);
	
	$resultRoom = mysql_query("SELECT * FROM ROOMS WHERE PRTID ='$PRTID';");
	if (!$resultRoom) die ("Database access failed: " . mysql_error());
	$resultImprov = mysql_query("SELECT * FROM IMPROVEMENTS WHERE PRTID ='$PRTID';");
	if (!$resultImprov) die ("Database access failed: " . mysql_error());
}


if($editmode || $addmode )
{
	echo('<form action="?page=property-view" method="post"> <pre>');
	
	echo('<table border=0 width=100>');
	echo('<TR>');
	echo('<TH>Property Info</TH>');
	echo('<TH>Rooms</TH>');
	echo('<TH>Improvements</TH>');
	echo('</TR>');
	echo('<TR><TD>');
	echo('<table border=2 width=100>');
	echo '<th>EXPIRY DATE</th><th><input type="text" name="EXPIRY_DATE" value=""/></th> </tr>';
	for ($i = 0 ; $i < $cols ; ++$i) 
	{
		$colname = mysql_result($colresult,$i,'COLUMN_NAME');
		if ($colname != 'USRID_SELLS' && $colname != 'USRID_BUYS' && $colname != 'PRTID')
		{
		
			if($colname != "ADRID")
				echo ('<tr> <th>' . $colname . '</th>');
			
			switch($colname)
			{
				case 'ADRID':
				{
					echo "<tr> <th><b><u>Address</u></b></th>  <th></th> </tr>";
					if($editmode)
					{
						$adrquery = "SELECT * FROM ADDRESS WHERE $colname='$row[$i]';";
						$adrresult = mysql_query($adrquery);
						if (!$adrresult) die ("Database access failed: " . mysql_error());
						$adrrow = mysql_fetch_row($adrresult);
					}
					for ($j = 0 ; $j < $adrcols ; ++$j) 
					{
						$adrcolname = mysql_result($adrcolresult,$j,'COLUMN_NAME');
						
						if ($adrcolname != $colname)
						{
							echo ('<tr> <th>' . $adrcolname . '</th>');
							echo '<th><input type="text" name=' .$adrcolname . ' value="';
							if($editmode) echo $adrrow[$j]; 
							echo '"/></th> </tr>';
						}
					}
					break;
				}
				case 'COMMENTS':
				{
					echo '<th><TEXTAREA NAME=' . $colname . ' ROWS=4 COLS=40>';
					if($editmode)echo $row[$i];
					echo '</TEXTAREA></th> </tr>';
					break;
				}
				case 'PROPERTY_TYPE':
				case 'HEATING_TYPE':
				case 'COOLING_TYPE':
				{
					echo('<th>' .create_combobox($colname,$colname,false,($editmode)?$row[$i]:0) .'</th> 
</tr>');
					break;
				}
				case 'ZONING':
				{
					echo('<th>' .create_combobox("ZONING_TYPE",$colname,false,($editmode)?$row[$i]:0) .'</th> 
</tr>');
					break;
				}
				default:
				{
					echo'<th><input type="text" name=' .$colname . ' value="';
					if($editmode)echo $row[$i];
					echo '"/></th> </tr>';
					break;
				}
			}

		}
	}
	echo ('</table>');
	echo('</TD>');
//ROOMS
	echo('<TD>');
	
	echo('<table border=2>');
	echo'<TR>';
		for ($i = 0 ; $i < $colsRooms ; ++$i) 
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			
			
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				echo ('	<th>' . $colname . '</th>');
			}
		}
	echo'</TR>';
	$x = 0;
	if($editmode)
	{
		while($row = mysql_fetch_row($resultRoom))
		{
		
			echo '<TR>';
			for ($i = 0 ; $i < $colsRooms ; ++$i) 
			{
				$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			
				if ($colname != 'ROMID' && $colname != 'PRTID')
				{
					echo('<th><input type="text" name=' .$colname . $x . ' value="' . $row[$i] . '"/></th>');
				}
			}
			$x++;
			echo '</TR>';
		}
	if(isset($_POST['addroom']))
	{
		echo '<TR>';
		for ($i = 0 ; $i < $colsImprov ; ++$i) 
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
		
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				echo('<th><input type="text" name=' .$colname . $x . ' value="..."/></th>');
			}
		}
		echo '</TR>';
	}
		echo('<form action="?page=property-view" method="post">');
		echo('<input type="hidden" name="addroom" value="yes"/>');
		echo('<input type="submit" value="Add Room"/>');
		echo('</form>');
	}
	echo('</table>');
	echo('</TD>');
//IMPROVEMENTS
	echo ('<TD>');
	echo('<table border=2>');
	echo'<TR>';
		for ($i = 0 ; $i < $colsImprov ; ++$i) 
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			
			
			if ($colname != 'IMTID' && $colname != 'PRTID')
			{
				echo ('	<th>' . $colname . '</th>');
			}
		}
	echo'</TR>';

	$x = 0;
	if($editmode)
	{
		while($row = mysql_fetch_row($resultImprov))
		{
			echo '<TR>';
			for ($i = 0 ; $i < $colsImprov ; ++$i) 
			{
				$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			
				if ($colname != 'IMTID' && $colname != 'PRTID')
				{
					echo('<th><input type="text" name=' .$colname . $x . ' value="' . $row[$i] . '"/></th>');
				}
			}
			echo '</TR>';
			$x++;
		}
	if(isset($_POST['addimprov']))
	{
		echo '<TR>';
		for ($i = 0 ; $i < $colsImprov ; ++$i) 
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
		
			if ($colname != 'IMTID' && $colname != 'PRTID')
			{
				echo('<th><input type="text" name=' .$colname . $x . ' value="..."/></th>');
			}
		}
		echo '</TR>';
	}

		echo('<form action="?page=property-view" method="post">');
		echo('<input type="hidden" name="addimprov" value="yes"/>');
		echo('<input type="submit" value="Add Improvement"/>');
		echo('</form>');
	}
	echo '</table>';
	echo('</TD>');
	echo('</TR>');
	echo('<TR>');
	echo ('<TD colspan=3>IMAGES should go here');
	echo('</TD>');
	echo('</TR>');
	echo ('</table>');
	echo('</pre>');

	echo ('<table>');
	echo('<TR>');
	echo('<TD>');
	echo'<input type="hidden" name="';
		if($editmode)echo 'save';
		else echo 'saveadd';
		echo '" value="yes"/>';
	echo('<input type="submit" value="Save"/>');
	echo('</form>');

	if($editmode)
	{
		echo('</TD>');
		echo('<TD>');
		echo('<form action="?page=property-view" method="post">');
		echo('<input type="hidden" name="delete" value="yes"/>');
		echo('<input type="submit" value="Delete this property"/>');
		echo('</form>');
	
	}
	echo('</TD>');
	echo('</TR>');
	echo ('</table>');
}
//SIMPLE VIEW
elseif (!$deletemode)
{
	$owns = false;
	$owner = '';
	echo('<table border=0 width=100>');
	echo('<TR>');
	echo('<TH>Property Info</TH>');
	echo('<TH>Rooms</TH>');
	echo('<TH>Improvements</TH>');
	echo('</TR>');
	echo('<TR><TD>');
	echo('<table border=2 width=100>');


	for ($i = 0 ; $i < $cols ; ++$i) 
	{
		$colname = mysql_result($colresult,$i,'COLUMN_NAME');
		
		if($colname == 'ADRID')
		{
			echo "<tr> <th><b><u>Address</u></b></th>  <th></th> </tr>";
			$adrquery = "SELECT * FROM ADDRESS WHERE $colname='$row[$i]';";
			$adrresult = mysql_query($adrquery);
			if (!$adrresult) die ("Database access failed: " . mysql_error());
			$adrrow = mysql_fetch_row($adrresult);
			$adrcolquery = "SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_NAME='ADDRESS';";
			$adrcolresult = mysql_query($adrcolquery);
			$adrcols = mysql_num_rows($adrcolresult);
			for ($j = 0 ; $j < $adrcols ; ++$j) 
			{
				$adrcolname = mysql_result($adrcolresult,$j,'COLUMN_NAME');
				if ($adrcolname != 'ADRID')
					echo ('	<tr> <th>' . $adrcolname . '</th>  <th>' . nl2br($adrrow[$j]) . '</th> </tr>');
			}
		}else if ($colname == 'USRID_SELLS')
		{
			$owns = ($row[$i] == $_SESSION['USRID']);
			$owner = $row[$i];
		}else if ($colname != 'USRID_BUYS' && $colname != 'PRTID')
		{
			echo ('	<tr> <th>' . $colname . '</th>  <th>' . nl2br($row[$i]) . '</th> </tr>');
		}
	}
	echo ('</table>');
	echo('</TD>');
	echo ('<TD>');
	
	echo('<table border=2>');
	echo'<TR>';
		for ($i = 0 ; $i < $colsRooms ; ++$i) 
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			
			
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				echo ('	<th>' . $colname . '</th>');
			}
		}
	echo'</TR>';
	
	while($row = mysql_fetch_row($resultRoom))
	{
		echo '<TR>';
		for ($i = 0 ; $i < $colsRooms ; ++$i) 
		{
			$colname = mysql_result($colsRoomResult,$i,'COLUMN_NAME');
			
			if ($colname != 'ROMID' && $colname != 'PRTID')
			{
				echo ('	<th>' . nl2br($row[$i]) . '</th>');
			}
		}
		echo '</TR>';
	}
	echo('</table>');
	echo('</TD>');
	echo ('<TD>');
	echo('<table border=2>');
	echo'<TR>';
		for ($i = 0 ; $i < $colsImprov ; ++$i) 
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			
			
			if ($colname != 'IMTID' && $colname != 'PRTID')
			{
				echo ('	<th>' . $colname . '</th>');
			}
		}
	echo'</TR>';
	while($row = mysql_fetch_row($resultImprov))
	{
		echo '<TR>';
		for ($i = 0 ; $i < $colsImprov ; ++$i) 
		{
			$colname = mysql_result($colsImprovResult,$i,'COLUMN_NAME');
			
			if ($colname != 'IMTID' && $colname != 'PRTID')
			{
				echo ('	<th>' . nl2br($row[$i]) . '</th>');
			}
		}	
		echo '</TR>';
	}
	echo '</table>';
	echo('</TD>');
/*	echo('<TD>');
	
	if(isset($_SESSION['USRID']) && $_SESSION['USRID'] != -1)
	{
		if (isset($month) && $month == "") { $month = $d["mon"]; } 
		if (isset($year) && $year == "") { $year = $d["year"]; }
		
		$cal = new Calendar; 
		//echo $cal->getMonthView($month,$year);
	}
	echo('</TD>');*/
	echo('</TD>');
	echo('</TR>');
	echo('<TR>');
	echo ('<TD colspan=3>IMAGES should go here');
	echo('</TD>');
	echo('</TR>');

	echo ('</table>');
	
	// EDIT ONLY IF IT BELONGS TO ME
	if($owns || $_SESSION['group'] == "SYSADMIN"){
		echo('<form action="?page=property-view" method="post">');
		echo('<input type="hidden" name="edit" value="yes"/>');
		echo('<input type="submit" value="Edit"/>');
		echo('</form>');
		
	}
	if (!$owns || $_SESSION['group'] == "SYSADMIN")
	{
		if(!isset($_POST["appointment"]) && $owner != '')
		{
echo <<<_END
			<table>
			</TR>
			</TD>
			<form action="?page=new_message&to=$owner" method="post">
			<input type="hidden" name="Contact" value="yes"/>
			<input type="submit" value="Contact Owner"/>
			</form>
			</TD>
			<TD>
			<form action="?page=new_appointment&to=$owner" method="post">
			<input type="hidden" name="appointment" value="yes"/>
			<input type="submit" value="Request Appointment"/>
			</form>
			</TD>
			</TR>
			</table>
_END;
		}

		$query = "UPDATE LISTS SET HITS=HITS+1 WHERE PRTID=$PRTID AND EXPIRY_DATE > NOW()";
		$result = mysql_query($query);
		if (!$result) die ("Database access failed: " . mysql_error());
	}
}

include('disconnect.php');
?>

